<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Inteligencia Computacional - TP 1</title>
    <link href="tpl/estilo.css" rel="stylesheet" type="text/css">
    <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="vendor/flot/excanvas.min.js"></script><![endif]-->
    <script language="javascript" type="text/javascript" src="vendor/jquery-1.6.4.min.js"></script>
    <script language="javascript" type="text/javascript" src="vendor/flot/jquery.flot.js"></script>
    <script language="javascript" type="text/javascript" src="vendor/flot/jquery.flot.navigate.js"></script>
    <script language="javascript" type="text/javascript" src="vendor/flot/jquery.flot.symbol.js"></script> 


    <!-- Jquery UI -->
    <link type="text/css" href="vendor/jqui/css/smoothness/jquery-ui-1.8.16.custom.css" rel="stylesheet" />	
    <script type="text/javascript" src="vendor/jqui/jquery-ui-1.8.16.custom.min.js"></script>

    <script>
	$(function() {
		$( "#tabs" ).tabs();
	});
	</script>
 </head>
 <body>
<div class="demo-description" style="display: none; ">
<p>Click tabs to swap between content that is broken into logical sections.</p>
</div><!-- End demo-description -->
    <h1>Inteligencia Computacional - TP 1</h1>
    <div id="placeholder" style="width:99%;height:600px;"></div>

<script type="text/javascript">
var placeholder = $("#placeholder");
var data = [];
var plot;
$(function () {    
    var options = {
        xaxis: { zoomRange: [0.1, 100], panRange: [-10, 10] },
        yaxis: { zoomRange: [0.1, 100], panRange: [-10, 10] },
        zoom: { interactive: true },
        pan: { interactive: true },
        grid: { hoverable: true, clickable: true },
        legend: { position: 'sw' }        
    };
    plot = $.plot(placeholder, data, options);
    
    // show pan/zoom messages to illustrate events 
    placeholder.bind('plotpan', function (event, plot) {
    var axes = plot.getAxes();
    $(".message").html("Panning en x: "  + axes.xaxis.min.toFixed(2)
           + " &ndash; " + axes.xaxis.max.toFixed(2)
           + " e y: " + axes.yaxis.min.toFixed(2)
           + " &ndash; " + axes.yaxis.max.toFixed(2));
    });
    placeholder.bind('plotzoom', function (event, plot) {
    var axes = plot.getAxes();
            $(".message").html("Zooming en x: "  + axes.xaxis.min.toFixed(2)
               + " &ndash; " + axes.xaxis.max.toFixed(2)
               + " e y: " + axes.yaxis.min.toFixed(2)
               + " &ndash; " + axes.yaxis.max.toFixed(2));
    });

    $("#placeholder").bind("plotclick", function (event, pos, item) {
        if (item) {
            alert("Has seleccionado un punto de la serie" + item.series.label + " cuyas coordenadas son . ( " +pos.x.toFixed(4)+ " , " + pos.y.toFixed(4) +" )");
            console.debug("Here is blah: %o", pos);
            //plot.highlight(item.series, item.datapoint);
        }
    });


    //FUNCIONES PARA AJAX   
     $("input.icajax").click(function () {
        var button = $(this);
        
        // buscamos la url a la cual hace referencia el boton
        var dataurl = button.siblings('a').attr('href');
 
        // fetcheo la info con JQ
        function onDataReceived(series) {
            
            //button.siblings('span').text('Fetched ' + series.label + ', first point: ' + firstcoordinate);
            //alert(series.length);

            var n = series.length;
            for (var i = 0; i < n; i++) 
                data.push(series[i]);
            
            // and plot all we got
            $.plot(placeholder, data, options);
         }
        
        $.ajax({
            url: dataurl,
            method: 'GET',
            dataType: 'json',
            success: onDataReceived
        });
    });

     $("input.clear").click(function () {
        data = [];
        $.plot(placeholder, data, options);
    });

    $(".button").click(function() {
	$(".loader").attr("style", 'display:visible');
	$("#ej1").fadeOut();
	var dataString =  '&cantEntradas='+ $("input#cantEntradas").val() + 
				  '&tasaAprendizaje=' + $("input#tasaAprendizaje").val() + 
				  '&nombreFuncActivacion=' + $("input#nombreFuncActivacion").val()	+
				  '&epocas=' + $("input#epocas").val();
	
	 //alert (dataString);return false;     
	 // validate and process form here	
	 $.ajax({
		 type: "POST",
		 url: "ejercicio1.php?item=2",
		 dataType: 'json',
		 data: dataString,
		 success: function(series) {
				var n = series.length;
				for (var i = 0; i < n; i++) {
					var ordenada = series[i][0]/series[i][2];
					var pendiente = -1*(series[i][1]/series[i][2]);
					data.push({ label: "t=" + i,  data: [[-1.5, ordenada + pendiente*-1.5  ], [1.5, ordenada + pendiente*1.5]] , lines: { show: true } });
				}
				$(".loader").attr("style", 'display:none');
				$("#ej1").fadeIn();
				$.plot(placeholder, data , options);
		 }
	});
     return false;
});
	
  });
  
</script>
<div id="tabs" style="width: 99%">
	<ul>
		<li><a href="#tabs-1">Ejercicio 1</a></li>
		<li><a href="#tabs-2">Ejercicio 2</a></li>
		<li><a href="#tabs-3">Ejercicio 3</a></li>
	</ul>
	<div id="tabs-1">
    <span><input class="icajax" type="button" value="Graficar Puntos"/><a target="_blank" href="ejercicio1.php?item=1">data</a></span> 
    <p>
        <input class="clear" type="button" value="Limpiar Screen"/>
        
        <style type="text/css">
            label { display: block;}
            input { clear: both; }
        </style>
        
        <form name="neurona" id="ej1" action="">
    <label for="cantEntradas" id="name_label">Cantidad de Entradas</label>
    <input type="text" name="cantEntradas" id="cantEntradas" size="30" value="2" class="text-input" />
    
    <label for="tasaAprendizaje" id="name_label">Tasa de Aprendizaje</label>  
    <input type="text" name="tasaAprendizaje" id="tasaAprendizaje" size="30" value="0.04" class="text-input" />
    
    <label for="nombreFuncActivacion" id="name_label">Funcion de Activacion (debe estar definida en utiles)</label>  
    <input type="text" name="nombreFuncActivacion" id="nombreFuncActivacion" size="30" value="signo" class="text-input" />
    
    <label for="epocas" id="name_label">Epocas de Entrenamiento</label>  
    <input type="text" name="epocas" id="epocas" size="30" value="500" class="text-input" />
    
    <input type="submit" name="submit" class="button" id="submit_btn" value="Entrenar" /> 
    

    
</form>
<span class="loader" style="display: none">Espere por favor. Trabajo en Proceso...<img src="tpl/ajax-loader.gif" alt="loading" /></span>
    </p>
	</div>
	<div id="tabs-2">
		<p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
	</div>
	<div id="tabs-3">
		<p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
		<p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
	</div>
</div>
        
 </body>
</html>
